package com.okaixz.client.controller;

import com.okaixz.client.model.dto.AppDto;
import com.okaixz.client.model.dto.WriteResultDto;
import com.okaixz.common.annotation.Anonymous;
import com.okaixz.common.client.Result;
import com.okaixz.common.core.controller.BaseController;
import com.okaixz.common.core.page.TableDataInfo;
import com.okaixz.manager.app.domain.App;
import com.okaixz.manager.app.service.IAppService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 讯飞智能体Controller
 *
 * @author ruoyi
 * @date 2024-08-20
 */
@RestController
@RequestMapping("/app")
@Api("客户端智能体模块")
@Anonymous
@Slf4j
public class ClientAppController extends BaseController
{
    @Autowired
    private IAppService appService;

    /**
     * 查询讯飞智能体列表
     */
    @GetMapping("/list")
    @ApiOperation("智能体列表查询接口")
    public TableDataInfo list(App app)
    {
        startPage();
        return appService.clientSelectAppList(app);
    }
    /**
     * 查询讯飞智能体列表
     */
    @GetMapping("/hotlist")
    @ApiOperation("热门应用接口")
    public TableDataInfo hostlist(App app)
    {
        startPage();
        return appService.clientSelectHotAppList(app);
    }

    @PostMapping("/write")
    public Result<WriteResultDto> write(@RequestParam(name = "appId", required = true) Long appId
            , @RequestParam(name = "input", required = true) String input
    ) {
        return Result.success(appService.write(appId, input));
    }
    @GetMapping("/{id}")
    public Result<AppDto> getAppById(@PathVariable(name = "id",required = true) Long id
    ) {
        App app = appService.selectAppById(id);
        AppDto appDto=null;
        if (app != null) {
            appDto=new AppDto();
            BeanUtils.copyProperties(app,appDto);
        }
        return Result.success(appDto);
    }
}
